"""
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
@Project : autotest
@File : login_page.py
@Author : zjx
@Time : 2022/11/18 19:49

"""
from selenium.webdriver.common.by import By

from base.ObjectMap import ObjectMap
from base.LoginBase import LoginBase
from config.yaml_config import GetConfig


class LoginPage(LoginBase, ObjectMap):

    def login_input_value(self, driver, input_placeholder, input_value):
        input_xpath = self.login_input(input_placeholder)
        # return driver.find_element_by_xpath(input_xpath).send_keys(input_value)
        return self.element_fill_value(driver, By.XPATH, input_xpath, input_value)

    def click_login(self, driver, button_name):
        button_xpath = self.login_button(button_name)
        # return driver.find_element_by_xpath(button_xpath).click()
        return self.element_click(driver, By.XPATH, button_xpath)

    def login(self, driver, user):
        """
        登录
        :param driver:
        :param user:
        :return:
        """
        self.element_to_url(driver, '/login')
        username, password = GetConfig().get_username_password(user)
        self.login_input_value(driver, '用户名', username)
        self.login_input_value(driver, '密码', password)
        self.click_login(driver, '登录')

    def login_assert(self, driver, image_name):
        """

        :param driver:
        :param image_name:
        :return:
        """
        return self.find_image_source(driver, image_name)
